package tech.aistar.pojo;

import lombok.*;

import java.io.Serializable;

/**
 * 控制层统一返回的对象
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@RequiredArgsConstructor//配置@NonNull
public class Result<T> implements Serializable {
    //状态码
    @NonNull
    private String code;

    //备注信息
    @NonNull
    private String msg;

    //查询结果
    private T data;

    //响应成功 - 查询
    public static <T> Result<T> success(T data) {
        return new Result<>("200","query-success",data);
    }

    //响应成功 - 非查询,可能insert,update,delete
    public static <T> Result<T> success() {
        return new Result<>("200","update-success");
    }

    //响应失败 - 响应的信息 - 排除问题
    public static <T> Result<T> fail() {
        return new Result<>("500","fail-error");
    }
}